package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppMessageRecord;
import com.vf.admin.miaodong.entity.AppPingtaiHuodong;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 平台活动
 */
@Repository
public class AfterPingtaiHuodongDao extends BaseDao<AppPingtaiHuodong> {

    /**
     * 查询列表
     */
    public List<AppPingtaiHuodong> findList(Map<String,Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_pingtai_huodong where 1=1  ");
        if (StringEx.isNotNull(paraMap.get("title"))) {
            sbStr.append(" and title like ? ");
            paramList.add("%"+paraMap.get("title")+"%");
        }
        if (StringEx.isNotNull(paraMap.get("state"))) {
            sbStr.append(" and state = ? ");
            paramList.add(paraMap.get("state"));
        }
        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppPingtaiHuodong.class,splitPage);
    }


    /**
     * 详情
     */
    public AppPingtaiHuodong get(Integer id) {
        if (id==null || id<=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_pingtai_huodong where id = ?  ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppPingtaiHuodong.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppPingtaiHuodong pojo) {
        if (pojo!=null && pojo.getId() != null && pojo.getId() > 0) {
            this.update(pojo);
        } else {
            pojo.setId(this.add(pojo));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id==null || id <= 0) {
            return;
        }
        String sql = "delete  from app_pingtai_huodong where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

}
